package com.youhome.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.youhome.mapper.HouseMapper;
import com.youhome.model.House;
import com.youhome.model.ListHubList;
import com.youhome.model.ListHubParam;
import com.youhome.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created by chen365 on 2018/12/05.
 */
@Service
public class HouseServiceImpl implements HouseService {
    @Autowired
    private HouseMapper houseMapper;

    @Override
    public House selectByPrimaryKey(String houseId) {
        return houseMapper.selectByPrimaryKey(houseId);
    }

    @Override
    public int selectCountByZips(ListHubParam record) {
        return houseMapper.selectCountByZips(record);
    }

    @Override
    public PageInfo<ListHubList> selectFavouriteByUserId(Integer pageIndex, Integer pageSize, Long userId) {
        if (StringUtils.isEmpty(pageIndex) || pageIndex < 1) {
            pageIndex = 1;
        }
        if (StringUtils.isEmpty(pageSize) || pageSize < 10) {
            pageSize = 10;
        }
        PageHelper.startPage(pageIndex, pageSize);
        List<ListHubList> list = houseMapper.selectFavouriteByUserId(userId);
        return new PageInfo<>(list);
    }
}
